<template>
  <el-dialog title="添加区段" :modelValue="visiable" width="500px" @close="emit('closed')">
    <el-form :model="model" label-width="60px" :inline="false" v-if="model">
      <!-- 名称 -->
      <el-form-item label="名称">
        <el-input v-model="model.name">
          <template #suffix>
            <ApplicationOne theme="outline" size="18" fill="#888" />
          </template>
        </el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="emit('closed')">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script setup lang="ts">
import useZone from '@/composables/useZone'
import { ApplicationOne } from '@icon-park/vue-next'
import { ElMessage } from 'element-plus'
import { ref } from 'vue'

const prop = defineProps<{
  visiable: boolean
  projId: number
}>()
const emit = defineEmits(['closed'])

const model = ref<ZoneModel>({
  name: '',
  isData: false,
})
const { add } = useZone()

async function onSubmit() {
  await add({ name: model.value!.name, projId: prop.projId, isData: false })
  ElMessage({
    type: 'success',
    message: '添加成功',
  })
  emit('closed')
}
</script>

<style></style>
